/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import {ECOption} from '@/libs/global/echarts'
import {iconUrl} from '@/libs/baseUrl'
/**每个option使用前请先克隆，以免使用过程中修改，导致原数据变动 */

export function getCityName(name: string): string {
  if (name.indexOf('黑龙江') !== -1) {
    return '黑龙江'
  }
  return name.substring(0, 2)
}
/**全国地图 option*/
export const chinaMapOption: ECOption = {
  legend: {},
  grid: {
    top: '16%'
  },
  geo: {
    map: 'china',
    show: true,
    roam: true,
    zoom: 1.4,
    layoutCenter: ['50%', '40%'],
    layoutSize: '100%',
    label: {
      show: true,
      formatter({name}: {name: string}) {
        return getCityName(name)
      },
      color: '#fff',
      textShadowColor: '#051b5f',
      textShadowBlur: 1,
      textShadowOffsetX: 2,
      fontSize: 14,
      fontWeight: 'bold',
      fontStyle: 'italic'
    },
    emphasis: {
      itemStyle: {
        areaColor: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: '#c7e9ff' // 0% 处的颜色
            },
            {
              offset: 1,
              color: '#dbfeff' // 100% 处的颜色
            }
          ],
          global: false // 缺省为 false
        }, //悬浮区背景
        borderWidth: 5,
        borderColor: '#74b2f5'
      },
      label: {
        show: true,
        color: '#fff',
        formatter({name}: {name: string}) {
          return getCityName(name)
        },
        textShadowColor: '#051b5f',
        textShadowBlur: 1,
        textShadowOffsetX: 2,
        fontSize: 14,
        fontWeight: 'bold',
        fontStyle: 'italic'
      }
    },
    select: {
      itemStyle: {
        areaColor: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: '#c7e9ff' // 0% 处的颜色
            },
            {
              offset: 1,
              color: '#dbfeff' // 100% 处的颜色
            }
          ],
          global: false // 缺省为 false
        }, //悬浮区背景
        borderWidth: 5,
        borderColor: '#74b2f5'
      },
      label: {
        show: true,
        color: '#fff',
        formatter({name}: {name: string}) {
          return getCityName(name)
        },
        textShadowColor: '#051b5f',
        textShadowBlur: 1,
        textShadowOffsetX: 2,
        fontSize: 14,
        fontWeight: 'bold',
        fontStyle: 'italic'
      }
    },
    itemStyle: {
      areaColor: {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [
          {
            offset: 0,
            color: '#c7e9ff' // 0% 处的颜色
          },
          {
            offset: 1,
            color: '#dbfeff' // 100% 处的颜色
          }
        ],
        global: false // 缺省为 false
      }, //悬浮区背景
      color: {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [
          {
            offset: 0,
            color: '#c7e9ff' // 0% 处的颜色
          },
          {
            offset: 1,
            color: '#dbfeff' // 100% 处的颜色
          }
        ],
        global: false // 缺省为 false
      },
      borderColor: '#81bbf6' //线
    }
  },
  series: [
    {
      type: 'map',
      map: 'china',
      geoIndex: 0,
      animation: false,
      data: []
    },
    {
      name: '区域设备分布数量',
      type: 'effectScatter',
      coordinateSystem: 'geo',
      geoIndex: 0,
      showEffectOn: 'emphasis',
      symbol(value: number[]): string {
        if (value[2] < 50) {
          return 'image://' + iconUrl('screen-scatter-symbol-normal')
        }
        return 'image://' + iconUrl('screen-scatter-symbol-warning')
      },
      symbolSize: [30, 35],
      label: {
        show: true,
        formatter({data}): string {
          if (Array.isArray(data)) {
            return data[2] as string
          }
          return data as string
        },
        color: '#fff',
        fontSize: 12,
        align: 'center'
      },
      data: [],
      emphasis: {
        scale: true
      },
      zlevel: 1
    }
  ]
}

/**节点echarts */
export const nodeOption = {
  // radius: "5%",
  type: 'tree',
  backgroundColor: 'rgba(0,0,0,0)',
  top: '50%',
  tooltip: {
    //提示框
    formatter: '{b}',
    trigger: 'item',
    triggerOn: 'mousemove',
    backgroundColor: 'rgba(1,70,86,1)',
    borderColor: 'rgba(0,246,255,1)',
    color: '#eee',
    borderWidth: 0.5,
    textStyle: {
      fontSize: 10,
      color: '#ccc'
    },
    extraCssText: 'width:200px; white-space:pre-wrap'
  },
  series: [
    {
      type: 'tree',
      emphasis: {
        scale: true
      },
      data: null,
      top: 28,
      bottom: 28,
      left: 0,
      right: 0,
      layout: 'radial',
      symbol: 'circle',
      symbolSize: 10,
      nodePadding: 20,
      animationDurationUpdate: 750,
      expandAndCollapse: false, //子树折叠和展开的交互，默认打开
      initialTreeDepth: 2,
      roam: true, //是否开启鼠标缩放和平移漫游。scale/move/true
      focusNodeAdjacency: true,
      itemStyle: {
        borderWidth: 10
      },
      label: {
        //标签样式
        color: '#e7e9eb',
        fontSize: 13,
        fontFamily: 'SourceHanSansCN',
        position: 'inside',
        rotate: 0
      },
      lineStyle: {
        width: 1,
        curveness: 0.5
      }
    }
  ]
}
